from django.db import models
from django.contrib.auth.models import AbstractUser

from .services import get_default_uuid


class User(AbstractUser):
    """
    用户模块
    """
    uuid = models.CharField(max_length=32, editable=False, blank=False, unique=True, default=get_default_uuid)
    "用户"
    username = models.CharField(max_length=255, unique=True, verbose_name="用户名")
    "姓名"
    fullname = models.CharField(max_length=24, blank=False, default="", verbose_name="姓名")
    "简介"
    bio = models.TextField(null=False, blank=True, default="", verbose_name="简介")
    "电话"
    phone = models.CharField(max_length=12, blank=True, default="", verbose_name="电话")
    "头像"
    avatar = models.CharField(max_length=128, null=True, blank=True, verbose_name="头像")
    "超级管理员"
    is_superuser = models.BooleanField(null=False, blank=False, default=False, verbose_name="管理员")
    "活跃"
    is_active = models.BooleanField(null=False, blank=False, default=True, verbose_name="活跃用户")
    "加入日期"
    date_joined = models.DateTimeField(auto_now_add=True, verbose_name="date joined")

    class Meta:
        verbose_name = "user"
        verbose_name_plural = "users"
        ordering = ["username"]

    def __str__(self):
        return self.get_full_name()

    def get_short_name(self):
        return self.username

    def get_full_name(self):
        return self.username or self.email


class Role(models.Model):
    """
    角色表
    """
    name = models.CharField(max_length=64, blank=False, unique=True, verbose_name="角色")
    description = models.TextField(blank=True, null=True, verbose_name="角色描述")


class RoleToUser(models.Model):
    """
    角色用户表
    """


class Menu(models.Model):
    """
    菜单表
    """
    name = models.CharField(max_length=64, blank=False, unique=True, verbose_name="菜单")
    role = models.ForeignKey(Role, on_delete=models.CASCADE, related_name='menu', verbose_name="角色")



